{% extends '::base.html.twig' %}

{% block title %}Lista subskrybentów{% endblock %}
 
{% block body %}
    
    {%block content %}
    <!-- content start -->
    <div class="well">
        <h1 class="heading">Subskrybenci</h1>
        <ul>
            <li>Wszystkich subskrybentów w bazie <span class="badge">{{subscribers|length}}</span></li>
        </ul>
        <a class="btn btn-primary btn-sm" href="{{path('wantuch_add_subscriber', {'_locale': g_locVar})}}">Dodaj nowego subskrybenta</a>
        <table class="table table-striped table-hover ">
            <thead>
                <tr>
                    <th>ID</th>
                    <th>Kampania</th>
                    <th>Imię</th>
                    <th>Nazwisko</th>
                    <th>Email</th>
                    <th>Token</th>
                    <th>Aktywny</th>
                    <th>Szczegóły</th>
                    <th>Edycja</th>
                </tr>
            </thead>
            <tbody>
            {% for subscriber in subscribers %}
                <tr>
                    <td>{{subscriber.id}}</td>
                    <td>{{subscriber.campaign}}</td>
                    <td>{{subscriber.name}}</td>
                    <td>{{subscriber.surname}}</td>
                    <td>{{subscriber.email}}</td>
                    <td>{{subscriber.token[:3]}}...</td>
                    <td>{{subscriber.active}}</td>
                    <td><a href="#" class="show-details-modal details-button" data-id="{{subscriber.id}}" data-toggle="modal" data-target="#detailsModal">Pokaż</a></td>
                    <td><a href="{{path("wantuch_edit_subscriber",{'id':subscriber.id})}}">Edytuj</a></td>
                </tr>
            {% endfor %}
            </tbody>
        </table>
        
    </div>
    <!-- Modal -->
    <div class="modal fade" id="detailsModal" tabindex="-1" role="dialog" aria-labelledby="detailsModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only"></span></button>
                    <h4 class="modal-title" id="detailsModalLabel">Szczegóły subskrybenta</h4>
                </div>
                <div class="modal-body">
                    
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary" data-dismiss="modal" >Zamknij</button>
                </div>
            </div>
        </div>
    </div>
    <!-- End modal --> 
    <!-- content end -->
    {% endblock %}
    {% block javascripts %}
        {{ parent() }}
        
        <script type="text/javascript">
            $(document).ready(function(){
                $('.details-button').on('click',function(){
                    
                    $.ajax({
                        type: "POST",
                        url: "{{path('wantuch_mailer_ajax_details_subscriber')}}",
                        data: { id: $(this).data("id") }
                    })
                        .done(function( msg ) {
                            $("#detailsModal .modal-body").html(msg.data);
                        });
                });
            });
        </script>
    {% endblock %}
    {% block footer %}{% endblock %}
{% endblock %} 